var a = require("../../utils/api.js"), t = getApp(), d = require("../../wxParse/wxParse.js");

Page({
    data: {
        curlist: 0,
        curcard: 0,
        showLoding: !0
    },
    onLoad: function(e) {
        var i = this;
        i.setData({
            showLoding: !1
        }), a.getMember({
            openid: t.globalData.openid
        }).then(function(a) {
            i.setData({
                user: a.data
            });
        }), a.markrting({
            op: "card_show",
            openid: t.globalData.openid
        }).then(function(a) {
            console.log(a), 0 == a.code && (i.setData({
                card: a.data.data.card,
                list: a.data.data.list,
                sid: a.data.data.card[0].id,
                id: a.data.data.list[0].id
            }), d.wxParse("article", "html", a.data.data.list[0].content, i, 5)), i.setData({
                showLoding: !0
            });
        });
    },
    selectlist: function(e) {
        var i = this, n = e.currentTarget.dataset.index, o = e.currentTarget.dataset.id;
        a.markrting({
            op: "card_show",
            openid: t.globalData.openid,
            id: o
        }).then(function(a) {
            console.log(a), i.setData({
                id: o,
                card: a.data.data.card,
                sid: a.data.data.card[0].id
            });
            for (var t = 0; t < a.data.data.list.length; t++) a.data.data.list[t].id == o && d.wxParse("article", "html", a.data.data.list[t].content, i, 5);
        }), i.setData({
            curlist: n,
            curcard: 0
        });
    },
    selectcard: function(a) {
        var t = this, d = a.currentTarget.dataset.index, e = a.currentTarget.dataset.id;
        t.setData({
            curcard: d,
            sid: e
        });
    },
    recharge: function(d) {
        var e = this;
        wx.showLoading({
            title: "加载中..."
        });
        var i = {
            id: e.data.id,
            sid: e.data.sid,
            openid: t.globalData.openid,
            op: "pay_card"
        };
        console.log(i), a.markrting(i).then(function(d) {
            console.log(d), wx.hideLoading(), console.log(d), 0 == d.code ? wx.requestPayment({
                timeStamp: d.data.data.timeStamp,
                nonceStr: d.data.data.nonceStr,
                package: d.data.data.package,
                signType: "MD5",
                paySign: d.data.data.paySign,
                success: function(e) {
                    wx.showToast({
                        title: "支付成功",
                        icon: "none",
                        duration: 2e3
                    }), a.markrting({
                        op: "card_pay",
                        openid: t.globalData.openid,
                        id: d.data.data.id
                    }).then(function(a) {
                        console.log(a), wx.navigateBack({
                            delta: 1
                        });
                    });
                },
                fail: function() {
                    wx.showToast({
                        title: "支付失败",
                        icon: "none",
                        duration: 2e3
                    });
                }
            }) : 0 != d.code && wx.hideLoading();
        });
    }
});